capture cd D:\Dropbox\book_welfare\replication\



 import delimited data\book_id_map.csv, clear 
	merge 1:1 book_id using data\bookid_oyear.dta
	keep if _merge==3 
	drop _merge 
	keep if oyear~=. 
	tempfile oyear 
	save `oyear'
	
	


use data\partial0.dta, clear 


forvalues j=1(1) 25 {
 append using data\partial`j'.dta 
}
 	

destring pubyr, replace 
destring author_id, replace 
destring book_id, replace 

keep pubyr book_id title isbn publisher author_id  


	merge 1:1 book_id using `oyear'
	
	replace pubyr = oyear if oyear~=. 
	drop if _merge==2 
	drop _merge 
	

* bring in the book-level data (genre)

merge 1:1 book_id using data\book_id_genres.dta


drop _merge 



merge m:1 author_id using data\author.dta

drop if  _merge == 2 
drop _merge 

preserve 
	use data\pennames_from_trussel_new.dta, clear
	keep penname rmshare 
	collapse (max) rmshare, by(penname)
	 
	tempfile pen 
	save `pen'
restore 

	gen penname=fullname 
	merge m:1 penname using `pen'
	drop if _merge==2 
	drop _merge 
	
	gen pmshare=mshare 
	
	replace pmshare = rmshare if rmshare~=.
	drop rmshare penname 


save data\books.dta, replace
